<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="pubsub.js"></script>
    <script type="text/javascript">

        //--------Test -------------//
        //一个主题 多个订阅者
        var Subscriber1 = function( topics , data ){
            console.log("Subscriber1 "+ topics + ": " + data );
        };
        var Subscriber2 = function( topics , data ){
            console.log("Subscriber2" + topics + ": " + data );
        };

        var testSubscription = pubsub.subscribe( 'example1', Subscriber1 );
        var testSubscription2 = pubsub.subscribe( 'example1', Subscriber2 );

        pubsub.publish( 'example1', 'hello world!' );
        pubsub.publish( 'example1', ['test','a','b','c'] );
        pubsub.publish( 'example1', [{'color':'blue'},{'text':'hello'}] );

        //取消订阅后再次发布则发布接收不到了
        setTimeout(function(){
            pubsub.unsubscribe( testSubscription );
            pubsub.unsubscribe( testSubscription2 );

        }, 0);

        pubsub.publish( 'example1', 'hello again!' );


    </script>
</head>
<body>

</body>
</html>